home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 1 / Cream of the Crop 1.iso / PROGRAM / CBASE102.ARJ / LSPUTRF.C < prev    next >
Text File  |  1991-09-23  |  3KB  |  113 lines

  1. /*    Copyright (c) 1989 Citadel    */
  2. /*       All Rights Reserved        */
  3.  
  4. /* #ident    "@(#)lsputrf.c    1.5 - 91/09/23" */
  5.  
  6. #include <ansi.h>
  7.  
  8. /* ansi headers */
  9. #include <errno.h>
  10. #ifdef AC_STDDEF
  11. #include <stddef.h>
  12. #endif
  13. #ifdef AC_STRING
  14. #include <string.h>
  15. #endif
  16.  
  17. /* library headers */
  18. #include <blkio.h>
  19.  
  20. /* local headers */
  21. #include "lseq_.h"
  22.  
  23. /*man---------------------------------------------------------------------------
  24. NAME
  25.      lsputrf - put field to current lseq record
  26.  
  27. SYNOPSIS
  28.      #include <lseq.h>
  29.  
  30.      int lsputrf(lsp, offset, buf, bufsize)
  31.      lseq_t *lsp;
  32.      size_t offset;
  33.      const void *buf;
  34.      size_t bufsize;
  35.  
  36. DESCRIPTION
  37.      The lsputrf function writes the contents of buf into a field in
  38.      the current record in lseq lsp.  The field begins offset
  39.      characters from the beginning of the record and is bufsize
  40.      characters long.  buf must point to a storage area at least
  41.      bufsize characters long.
  42.  
  43.      lsputrf will fail if one or more of the following is true:
  44.  
  45.      [EINVAL]       lsp is not a valid lseq pointer.
  46.      [EINVAL]       buf is the NULL pointer.
  47.      [EINVAL]       bufsize is 0.
  48.      [LSEBOUND]     offset + bufsize extends beyond the end
  49.                     of the record.
  50.      [LSELOCK]      lsp is not write locked.
  51.      [LSENOPEN]     lsp is not open.
  52.      [LSENREC]      The cursor is null.
  53.  
  54. SEE ALSO
  55.      lscursor, lsgetrf, lsputr.
  56.  
  57. DIAGNOSTICS
  58.      Upon successful completion, a value of 0 is returned.  Otherwise,
  59.      a value of -1 is returned, and errno set to indicate the error.
  60.  
  61. ------------------------------------------------------------------------------*/
  62. #ifdef AC_PROTO
  63. int lsputrf(lseq_t *lsp, size_t offset, const void *buf, size_t bufsize)
  64. #else
  65. int lsputrf(lsp, offset, buf, bufsize)
  66. lseq_t *lsp;
  67. size_t offset;
  68. const void *buf;
  69. size_t bufsize;
  70. #endif
  71. {
  72.     /* validate arguments */
  73.     if (!ls_valid(lsp) || buf == NULL || bufsize < 1) {
  74.         errno = EINVAL;
  75.         return -1;
  76.     }
  77.  
  78.     /* check if not open */
  79.     if (!(lsp->flags & LSOPEN)) {
  80.         errno = EINVAL;
  81.         return -1;
  82.     }
  83.  
  84.     /* check if not write locked */
  85.     if (!(lsp->flags & LSWRLCK)) {
  86.         errno = LSELOCK;
  87.         return -1;
  88.     }
  89.  
  90.     /* check if over record boundary */
  91.     if (offset + bufsize > lsp->lshdr.recsize) {
  92.         errno = LSEBOUND;
  93.         return -1;
  94.     }
  95.  
  96.     /* check if cursor is null */
  97.     if (lsp->clspos == NIL) {
  98.         errno = LSENREC;
  99.         return -1;
  100.     }
  101.  
  102.     /* copy field to current record */
  103.     memcpy(((char *)lsp->clsrp->recbuf + offset), buf, bufsize);
  104.  
  105.     /* write field */
  106.     if (ls_rcputf(lsp, lsp->clspos, offset, buf, bufsize) == -1) {
  107.         LSEPRINT;
  108.         return -1;
  109.     }
  110.  
  111.     return 0;
  112. }
  113.